package com.dandan.mobilelover.service.impl;

import java.util.List;

import javax.inject.Inject;

import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.dandan.mobilelover.component.Pagination;
import com.dandan.mobilelover.dao.ImageRepository;
import com.dandan.mobilelover.entity.Image;
import com.dandan.mobilelover.service.ImageService;

@Service
@Transactional
public class ImageServiceImpl implements ImageService{

	@Inject
	private ImageRepository imageRepository;
	
	@Override
	public void saveImage(Image book) {
		imageRepository.save(book);
	}

	@Override
	public List<Image> searchList(Pagination p) {
		 p.setTotalCount(imageRepository.count());
		  return imageRepository.findAllByPageAndSort(new PageRequest(p.getPage() -1, p.getPageSize()));
	}

}
